import 'package:mobx/mobx.dart';
import 'package:terminal_flutter_demo/pages/mobxpages/preferences/preferences_service.dart';

part 'mobx_counter.g.dart';

class MobxCounter = CounterBase with _$MobxCounter;

abstract class CounterBase with Store {
  CounterBase();

  CounterBase.preferences(this._preferencesService) {
    useDarkMode = _preferencesService.useDarkMode;
    useLanguage = _preferencesService.useLanguage;
  }

  late final PreferencesService _preferencesService;

  @observable
  bool useDarkMode = false;

  @observable
  String useLanguage = 'zh';

  @observable
  int count = 0;

  @computed
  bool get hasAddTen => count > 10;

  @action
  void increnment() {
    count++;
  }

  @action
  Future<void> setDarkMode({required bool value}) async {
    _preferencesService.useDarkMode = value;
    useDarkMode = value;
  }

  @action
  Future<void> setLanguage({required String value}) async {
    _preferencesService.useLanguage = value;
    useLanguage = value;
  }
}
